package cn.wk.org.service.impl;

import cn.wk.basic.service.impl.BaseServiceImpl;
import cn.wk.org.domain.DictionaryDetail;
import cn.wk.org.domain.DictionaryType;
import cn.wk.org.mapper.DictionaryDetailMapper;
import cn.wk.org.service.IDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DictionaryTypeServiceImpl extends BaseServiceImpl<DictionaryType> implements IDictionaryTypeService {
    @Autowired
    private DictionaryDetailMapper detailMapper;

    @Autowired
    private IDictionaryTypeService typeService;


    @Override
    public void deleteByDetail(Long id) {
        //查找所有的明细列表
        List<DictionaryDetail> details = detailMapper.findAll();
        //拿出每一次的明细列表
        for(DictionaryDetail detail:details){
            if(detail.getDictionaryType() != null){
                //拿出所有的dictionaryType
                Long type_id = detail.getDictionaryType().getId();
                if(type_id == id){
                    //删除
                    detailMapper.delete(type_id);
                }
            }
        }
        //删除一级
        typeService.delete(id);
    }
}
